package com.sqstudio.control
{
	import com.sqstudio.common.Sys;
	import com.sqstudio.event.CalendarEvent;
	import com.sqstudio.model.Model;
	import com.sqstudio.view.GridPanel;
	
	import flash.display.Sprite;
	import flash.events.Event;
	/**
	 *日期网格控制器 
	 * @author Nestor
	 * 
	 */	
	public class GridController extends Sprite
	{
		private var _gridPanel:GridPanel;
		public function GridController()
		{
			this._gridPanel = new GridPanel(Model.CrtDate);
			Sys.STAGE.addChild(this._gridPanel);
			this._gridPanel.x = 15; 
			this._gridPanel.y = 150; 
			CalendarEvent.Dispatcher.addEventListener(CalendarEvent.DATE_CHANGE,dateChangeHandler);
			CalendarEvent.Dispatcher.addEventListener(CalendarEvent.COUNT_CHANGE,countChangeHandler);
		}
		
		protected function countChangeHandler(e:CalendarEvent):void
		{
			if(int(e.data)==1){
				this._gridPanel.visible = true;
			}else if(int(e.data)== -1){
				this._gridPanel.visible = false;
			}
		}
		
		private function dateChangeHandler(e:CalendarEvent):void
		{
			this._gridPanel.updateGrid(Model.CrtDate);
		}		
		
	}
}